// Copyright 2022 Hollson. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package leetcode1

// https://blog.csdn.net/axsh_01/article/details/79835865
// 时间复杂度为O(log2n)
// 普通二分查找
func binarySearch(arr []int, target int) int {
	var low = 0
	var height = len(arr) - 1
	for low <= height {
		var mid = low + (height-low)/2
		if arr[mid] == target {
			return mid
		} else if arr[mid] < target {
			low = mid + 1
		} else if arr[mid] > target {
			height = mid - 1
		}
	}
	return -1
}
